import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/element/layout'
import LayoutM from '@/views/vant/layout'

Vue.use(VueRouter)

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/home',
    component: Layout,
    children: [
      {
        path: '',
        name: 'home',
        component: () => import('@/views/element/home'),
        meta: {
          title: '首页'
        }
      },
      {
        path: '/songlist',
        name: 'songlist',
        component: () => import('@/views/element/songlist'),
        meta: {
          title: '歌单列表'
        }
      },
      {
        path: '/newest',
        name: 'newest',
        component: () => import('@/views/element/newest'),
        meta: {
          title: '最新歌曲'
        }
      },
      {
        path: '/mvs',
        name: 'mvs',
        component: () => import('@/views/element/mvs'),
        meta: {
          title: 'mv列表'
        }
      },
      {
        path: '/search',
        name: 'search',
        component: () => import('@/views/element/search'),
        meta: {
          title: '搜索列表'
        }
      },
      {
        path: '/mv',
        name: 'mv',
        component: () => import('@/views/element/mv'),
        meta: {
          title: 'mv详情'
        }
      },
      {
        path: '/playlist',
        name: 'playlist',
        component: () => import('@/views/element/playlist'),
        meta: {
          title: '播放列表'
        }
      },
      {
        path: '/singer',
        name: 'singer',
        component: () => import('@/views/element/singer'),
        meta: {
          title: '歌手排行'
        }
      }
    ]
  },
  {
    path: '/m.home',
    component: LayoutM,
    children: [
      {
        path: '',
        name: 'm.home',
        component: () => import('@/views/vant/home'),
        meta: {
          title: '移动端首页'
        }
      },
      {
        path: '/m.myvideo',
        name: 'm.myvideo',
        component: () => import('@/views/vant/myvideo'),
        meta: {
          title: '移动端MV'
        }
      },
      {
        path: '/m.songlist',
        name: 'm.songlist',
        component: () => import('@/views/vant/songlist'),
        meta: {
          title: '歌单列表'
        }
      },
      {
        path: '/m.mvlist',
        name: 'm.mvlist',
        component: () => import('@/views/vant/mvlist'),
        meta: {
          title: 'MV列表'
        }
      },
      {
        path: '/m.singer',
        name: 'm.singer',
        component: () => import('@/views/vant/singer'),
        meta: {
          title: '歌手列表'
        }
      },
      {
        path: '/m.search',
        name: 'm.search',
        component: () => import('@/views/vant/search'),
        meta: {
          title: '移动端搜索'
        }
      },
      {
        path: '/m.robot',
        name: 'm.robot',
        component: () => import('@/views/vant/robot'),
        meta: {
          title: '移动端消息'
        }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
